<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
            //Conectar no Banco MYSQL
            $connect = mysql_connect('localhost', 'root', '');
            if (!$connect) {
                die('Não foi possível conectar: ' . mysql_error());
            }
            echo 'Conexão bem sucedida';
            //Seleção Banco de Dados
            $db_selected = mysql_select_db('web_xd', $connect);
            //Inserindo dados
            $login = $_POST['login'];
           
            if (!$result) {
                die('Invalid query: ' . mysql_error());
            }
            //Seleção de dados
            $usuario = $_POST['login'];
            $senha = $_POST['senha'];
            
            $result = mysql_query("select nm_usuario, nm_senha from usuario where nm_usuario = '".$usuario."' and nm_senha = '".$senha."';");
            if (!$result) {
                die('Invalid query: ' . mysql_error());
            }
            //Conectar no Banco MongoDB
            $connection = new MongoClient(); // connects to localhost:27017
            $db = $connection->test;
            
            //Inserindo dados no MongoDB e exibindo
            $db->users->insert(array("_id" => 2)); //Mesma coisa que db.users.insert()
            $collection = $db->users;

            $document = $collection->findOne();
            var_dump( $document );
            
            //Exemplo funcionamento do PHP Crawl
            include('PHPCrawl_082\PHPCrawl_082\libs\PHPCrawler.class.php');
            class MyCrawler extends PHPCrawler 
            {
              function handleDocumentInfo($DocInfo) 
              {
                // Just detect linebreak for output ("\n" in CLI-mode, otherwise "<br>").
                if (PHP_SAPI == "cli") $lb = "\n";
                else $lb = "<br />";

                // Print the URL and the HTTP-status-Code
                echo "Page requested: ".$DocInfo->url." (".$DocInfo->http_status_code.")".$lb;

                // Print the refering URL
                echo "Referer-page: ".$DocInfo->referer_url.$lb;

                // Print if the content of the document was be recieved or not
                if ($DocInfo->received == true)
                  echo "Content received: ".$DocInfo->bytes_received." bytes".$lb;
                else
                  echo "Content not received".$lb; 

                // Now you should do something with the content of the actual
                // received page or file ($DocInfo->source), we skip it in this example 

                echo $lb;

                flush();
              } 
            }

            // Now, create a instance of your class, define the behaviour
            // of the crawler (see class-reference for more options and details)
            // and start the crawling-process. 

            $crawler = new MyCrawler();

            // URL to crawl
            $crawler->setURL("www.php.net");

            // Only receive content of files with content-type "text/html"
            $crawler->addContentTypeReceiveRule("#text/html#");

            // Ignore links to pictures, dont even request pictures
            $crawler->addURLFilterRule("#\.(jpg|jpeg|gif|png)$# i");

            // Store and send cookie-data like a browser does
            $crawler->enableCookieHandling(true);

            // Set the traffic-limit to 1 MB (in bytes,
            // for testing we dont want to "suck" the whole site)
            $crawler->setTrafficLimit(1000 * 1024);

            // Thats enough, now here we go
            $crawler->go();

            // At the end, after the process is finished, we print a short
            // report (see method getProcessReport() for more information)
            $report = $crawler->getProcessReport();

            if (PHP_SAPI == "cli") $lb = "\n";
            else $lb = "<br />";

            echo "Summary:".$lb;
            echo "Links followed: ".$report->links_followed.$lb;
            echo "Documents received: ".$report->files_received.$lb;
            echo "Bytes received: ".$report->bytes_received." bytes".$lb;
            echo "Process runtime: ".$report->process_runtime." sec".$lb;  

        ?>
    </body>
</html>
